<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>待办列表</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css">
</head>

<body>
    <div id="app">
        <div class="container pt-5">
            <div class="card">
                <div class="card-header bg-dark text-white text-center">
                    <h3 class="card-title">待办列表</h3>
                </div>
                <div class="card-body">
                    <ul class="list-gruop list-group-flush px-0 m-0">
                        <li class="list-group-item d-flex pl-5" v-for="item,index in items" :key="index">
                            <div class="custom-checkbox">
                                <input type="checkbox" class="custom-control-input" :id="`item${index}`" disabled v-model="item.state">
                                <label class="custom-control-label" :for="`item${index}`"></label>
                            </div>
                            <span class="mr-auto">{{index+1}}-{{item.title}}</span>
                            <button class="btn btn-success btn-sm mr-1" v-if="!item.state" @click="ok(index)">完成</button>
                            <button class="btn btn-danger btn-sm" @click="del(index)">删除</button>
                        </li>
                    </ul>
                </div>
                <div class="card-footer bg-transparent">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="待办事项" v-model="title">
                        <div class="input-group-append">
                            <button class="btn btn-primary" @click="add">添加</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        let app = new Vue({
            el: "#app",
            data:{
                items:[
                    {title:'待办事项1',state:false},
                    {title:'待办事项2',state:true},
                    {title:'待办事项3',state:false}
                ],
                title:''
            },
            methods: {
                ok(index){
                    this.items[index].state = true
                },
                del(index){
                    this.items.splice(index,1)
                },
                add(){
                    let item = {title:this.title,state:false}
                    this.items.push(item)
                    this.title = ''
                }
            },
        })
    </script>
</body>

</html>